package com.gxa.controller;

import com.gxa.common.*;
import com.gxa.pojo.*;
import com.gxa.pojo.Contact;
import com.gxa.service.CustomerService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
*@Description: 客户相关接口
*@Author: LC
*@date: 2021/12/2
*/
@Controller
@RequestMapping("/customer")
@Api(value="客户管理接口Test",tags = "客户管理接口（李晨）")
public class CustomerController {

    @Autowired(required = false)
    CustomerService customerService;

    @ApiOperation(value = "查询客户信息", notes = "用分页的方式查询客户信息,返回的是客户数组", response = R.class)
    @RequestMapping(value = "/getPage", method = RequestMethod.POST)
    @ResponseBody
    public R getCustomerInfo(@RequestBody @ApiParam(name = "pageRecv", value = "分页json", required = true) PageRecv<CustomerSearch> pageRecv) {
        R r = customerService.getCustomerPage(pageRecv);
        return r;
    }

    @ApiOperation(value = "新增客户", notes = "新增一个客户", response = R.class)
    @RequestMapping(value = "/addCustomer", method = RequestMethod.POST)
    @ResponseBody
    public R addCustomer(@RequestBody @ApiParam(name = "customer", value = "新增的客户实体", required = true) Customer customer) {
        R r = customerService.addCustomer(customer);
        return r;
    }

    @ApiOperation(value = "修改客户", notes = "修改客户的信息，需要传入客户实体", response = R.class)
    @RequestMapping(value = "/modifyCustomer", method = RequestMethod.POST)
    @ResponseBody
    public R modifyCustomer(@RequestBody @ApiParam(name = "customer", value = "修改后的客户实体", required = true) Customer customer) {
        R r = customerService.modifyCustomer(customer);
        return r;
    }

    @ApiOperation(value = "批量移动客户到回收站", notes = "批量的将客户移到回收站中，传入的参数是一个客户id数组，若要移动一个客户也需要放到数组中，可复用该接口\n" +
            "需要：customerIds（客户id数组），remark（备注），delInfo（删除的关联信息编号）\n示例：{\n" +
            "\"customerIds\":[58],\n" +
            "\"remark\":\"回收站测试\",\n" +
            "\"delInfo\":[0]\n" +
            "}", response = R.class)
//    @ApiImplicitParam(name = "customerIds", value = "移动到回收站的客户id数组", paramType = "query", dataType = "Integer", allowMultiple = true, required = false)
    @RequestMapping(value = "/moveToTrash", method = RequestMethod.POST)
    @ResponseBody
//    public R moveToTrash(@RequestParam List<Integer> customerIds, @RequestParam String remark, @RequestParam List<Integer> delInfo) {
    public R moveToTrash(@RequestBody Map body) {
        R r = customerService.moveToTrash((List)body.get("customerIds"), (String)body.get("remark"), (List)body.get("delInfo"));
        return r;
    }

    @ApiOperation(value = "批量移动客户到公海", notes = "批量的将客户移到公海中，传入的参数是一个客户id数组，若要移动一个客户也需要放到数组中，可复用该接口", response = R.class)
//    @ApiImplicitParam(name = "customerIds", value = "移动到公海的客户id数组", paramType = "query", dataType = "Integer", allowMultiple = true, required = false)
    @RequestMapping(value = "/moveToCustomerPoll", method = RequestMethod.POST)
    @ResponseBody
    public R moveToCustomerPoll(@RequestBody @ApiParam(name = "customerIds", value = "移动到公海的客户id数组") List<Integer> customerIds) {
        R r = customerService.moveToCustomerPoll(customerIds);
        return r;
    }


    @ApiOperation(value = "客户搜索", notes = "搜索", response = R.class)
    @RequestMapping(value = "/getCustomerBySearch", method = RequestMethod.POST)
    @ResponseBody
    public R getCustomerBySearch(@RequestBody @ApiParam(name = "customerSearchPageRecv", value = "搜索条件类", required = true) PageRecv<CustomerSearch> customerSearchPageRecv) {
        R r = new R();
        r.setCode(200);
        r.setMsg(Constants.SUCCESS);
        Province province = new Province();
        province.setProvince_d(0);
        province.setProvince_name("四川省");
        City city = new City();
        city.setCity_id(0);
        city.setCity_name("成都市");
        city.setProvince(province);
        Contact contact = new Contact();
        contact.setContact_sex(0);
        contact.setContact_birthday(new Date());
        contact.setContact_email("1232132141@qq.com");
        contact.setContact_id(0);
        contact.setContact_remark("备注");
        contact.setContact_name("联系人李某");
        contact.setContact_phone("15122222222");
        contact.setContact_qq("1178721111");
        contact.setContact_wechat("SFEWFWE");
        contact.setPostion("老板");
        contact.setCustomer_id(0);
        Customer customer = new Customer();
        customer.setAddress("国信安");
        customer.setAttachment_url("/file/temp/2021120315616.doc");
        customer.setCity(city);
        customer.setConsultation("二建");
        List contacts = new ArrayList<>();
        contacts.add(contact);
        customer.setContact(contacts);
        customer.setCustomer_id(0);
        customer.setCustomer_name("某老板");
        customer.setEnable_protected(0);
        customer.setOrigin("电话联系");
        customer.setPost_code("6100000");
        customer.setProtected_deadline(30);
        customer.setType("已成交");
        customer.setStatus(1);
        customer.setRemark("大客户");
        Customer_Records customer_records = new Customer_Records();
        customer_records.setCustomer_id(0);
        customer_records.setImport_date(new Date());
        customer_records.setCustomer_records_id(0);
        customer_records.setImport_emp_id(0);
        customer_records.setUpdate_date(new Date());
        customer_records.setUpdate_emp_id(0);
        customer.setCustomer_records(customer_records);
        r.setData(customer);
        return r;
    }


    //------------------------------------
    @ApiOperation(value = "转移客户到指定业务员", notes = "把客户转交给指定的业务员对接\n" +
            "需要参数customerIds（客户id数组）,employeeId（转移业务员id，不是数组哦）", response = R.class)
    @RequestMapping(value = "/moveToOtherEmp", method = RequestMethod.POST)
//    @ApiImplicitParams ({
//            @ApiImplicitParam(name = "customerIds", value = "客户数组", required = true,allowMultiple = true),
//            @ApiImplicitParam(name = "employeeId", value = "业务员id", required = true) })
    @ResponseBody
//    public R moveToOtherEmp(@RequestParam List<Integer> customerIds,
//                            @RequestParam Integer employeeId) {
        public R moveToOtherEmp(@RequestBody Map body) {

        R r = customerService.moveToOtherEmp((List)body.get("customerIds"), (Integer)body.get("employeeId"));
        return r;
    }


    @ApiOperation(value = "获取指定条件的客户数量", notes = "在data中指定客户条件，返回数量", response = R.class)
    @RequestMapping(value = "/getCustomerCountByCondition", method = RequestMethod.POST)
    @ResponseBody
    public R getCustomerCountByCondition(@RequestBody @ApiParam(name = "pageRecv", value = "指定客户条件", required = true) PageRecv<CustomerSearch> pageRecv) {
        R r = customerService.getCustomerCountByCondition(pageRecv);
        return r;
    }


//    @ApiOperation(value = "获取指定时间范围客户新增数量", notes = "获取指定时间范围客户新增数量", response = R.class)
//    @RequestMapping(value = "/getCustomerCountByDate", method = RequestMethod.GET)
//    @ApiImplicitParams ({
//            @ApiImplicitParam(name = "startDate", value = "开始时间", required = true),
//            @ApiImplicitParam(name = "endDate", value = "结束时间", required = true) })
//    @ResponseBody
//    public R getCustomerCountByDate(@RequestParam @DateTimeFormat(pattern = "yyyy/MM/dd hh:mm:ss") Date startDate, @RequestParam @DateTimeFormat(pattern = "yyyy/MM/dd hh:mm:ss")Date endDate) {
//        R r = customerService.getCustomerCountByDate(startDate, endDate);
//        return r;
//    }


    @ApiOperation(value = "保护期例外设置", notes = "保护期例外设置\n" +
            "customerIds（客户id数组），protectedSetting（保护设置0（关闭），1（开启））", response = R.class)
    @RequestMapping(value = "/modifyCustomerProtectedSetting", method = RequestMethod.POST)
//    @ApiImplicitParams ({
//    @ApiImplicitParam(name = "customerIds", value = "客户id数组", required = true,allowMultiple = true),
//    @ApiImplicitParam(name = "protectedSetting", value = "保护设置0（关闭），1（开启）", required = true) })
    @ResponseBody
//    public R modifyCustomerProtectedSetting(@RequestParam List<Integer> customerIds,
//                                            @RequestParam Integer protectedSetting){
        public R modifyCustomerProtectedSetting(@RequestBody Map body){
        R r=customerService.modifyCustomerProtectedSetting((List)body.get("customerIds"),(Integer)body.get("protectedSetting"));
        return r;
    }





}
